package com.sys.db.action;

import java.util.List;


import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;
import com.sys.db.manager.DefJobManager;
import com.sys.db.manager.DefJobTypeParaManager;
import com.sys.pojo.DefJob;

public class DefJobAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List list=null;
	private DefJobManager defJobManager;
	private DefJobTypeParaManager defJobTypeParaManager;
	private DefJob defJob;
	private boolean success=true;
	private String message;
	private String datas;
	private String ids;
	private int count;
	private String start;
	private String limit;
	private String jobParaId;
	private List paraList;
	
	/**
	 * 列出所有job
	 * @return
	 */
	public String listJobs(){
		try {
			List listAll=defJobManager.findAll();
			if(start!=null&&limit!=null){
				list=defJobManager.findByPage(new Integer(start), new Integer(limit));
				count=listAll.size();
			}else{
				list=listAll;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 保存页面修改/新增数据
	 */
	public String saveJobs(){
		try {
			defJobManager.saveOrUpdate(datas);
		} catch (Exception e) {
			success=false;
			message=e.getMessage();
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	/**
	 * 删除选择的数据
	 */
	public String deleteJobs(){
		try {
			defJobManager.deleteByIds(ids);
		} catch (Exception e) {
			success=false;
			message=e.getMessage();
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	/**
	 * 根据ID查找作业参数
	 * @return
	 */
	public String findParaById(){
		try {
			if("all".equals(jobParaId)){
				paraList=defJobManager.findAllTypePara();
			}else if(jobParaId!=null&&jobParaId!="undefined"&&!"".equals(jobParaId)){
				paraList=defJobManager.findParaByJobId(jobParaId);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	@JSON(serialize=false)
	public DefJobManager getDefJobManager() {
		return defJobManager;
	}
	public void setDefJobManager(DefJobManager defJobManager) {
		this.defJobManager = defJobManager;
	}

	public DefJob getDefJob() {
		return defJob;
	}

	public void setDefJob(DefJob defJob) {
		this.defJob = defJob;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getDatas() {
		return datas;
	}

	public void setDatas(String datas) {
		this.datas = datas;
	}
	public String getIds() {
		return ids;
	}
	public void setIds(String ids) {
		this.ids = ids;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public String getStart() {
		return start;
	}
	public void setStart(String start) {
		this.start = start;
	}
	public String getLimit() {
		return limit;
	}
	public void setLimit(String limit) {
		this.limit = limit;
	}
	public List getParaList() {
		return paraList;
	}
	public void setParaList(List paraList) {
		paraList = paraList;
	}
	public String getJobParaId() {
		return jobParaId;
	}
	public void setJobParaId(String jobParaId) {
		this.jobParaId = jobParaId;
	}
	public DefJobTypeParaManager getDefJobTypeParaManager() {
		return defJobTypeParaManager;
	}
	public void setDefJobTypeParaManager(DefJobTypeParaManager defJobTypeParaManager) {
		this.defJobTypeParaManager = defJobTypeParaManager;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

	
}
